
import UiPanel from "../../lib/UiPanel";
import FPJDefine from "../../Game/FPJ/Prefabs/FPJDefine";

const { ccclass, property } = cc._decorator;

@ccclass
export default class Hall extends UiPanel {

	@property(cc.Sprite)
	bg:cc.Sprite = null;
	@property(cc.SpriteFrame)
	vipSpF:cc.SpriteFrame = null;
	@property(cc.SpriteFrame)
	hallSpF:cc.SpriteFrame = null;

	@property(cc.Node)
	UIRoot: cc.Node = null;
	@property(cc.Node)
	HallGame_Root: cc.Node = null;
	@property(cc.Prefab)
	hallUI: cc.Prefab = null;

	eventCustomHotUpError;
	eventOpenGame;

	from: string = "";
	isOpenChongZhi: boolean = false;

	private openedType: boolean[] = [false, false, false, false];
	//背景动画路径
	DWC_dt_bg_Path = "HallDWC/hall/Animation/DWC_dt_bg/Prefab/DWC_dt_bg";
	/** 通知 create by tm*/
	evtServerNtc: any = null;
	evtEnterVip:any = null;
	onLoad() {
		cc.vv.GLDefine.HoldScene = false;
		cc.vv.sceneName = "Hall";
		cc.vv.GLUtils.prohibitDoubleBtnClick();
		cc.vv.hotUpdate.init(null);
	}
	onEnable() {
		this.eventCustomHotUpError = cc.vv.eventCustom.on("hotUpError", this.hotUpError.bind(this), this.node);
		this.eventOpenGame = cc.vv.eventCustom.on("openGame", this.openGame.bind(this), this.node);
		//create by tm
		this.evtServerNtc = cc.vv.eventCustom.on("ServerNtc", this.ServerNtc.bind(this), this.node);
		this.evtEnterVip = cc.vv.eventCustom.on("EnterVipRoom", this.enterVipRoom.bind(this), this.node);
		cc.systemEvent.on("EnterTable",this.enterVipRoom.bind(this) );
	}

	MusicOn() {
		// cc.vv.audioUtil.playMusic(cc.vv.GLConfig.hallmusicpath[0]);
	}
	onDisable() {
		if (typeof this.eventCustomHotUpError != "undefined") {
			cc.vv.eventCustom.off("hotUpError", this.eventCustomHotUpError);
			this.eventCustomHotUpError = undefined;
		}

		if (typeof this.eventOpenGame != "undefined") {
			cc.vv.eventCustom.off("openGame", this.eventOpenGame);
			this.eventOpenGame = undefined;
		}
		//create by tm
		if (this.evtServerNtc) {
			cc.vv.eventCustom.off("ServerNtc", this.evtServerNtc);
			this.evtServerNtc = null;
		}
		//cc.vv.MarqueeDataModel.close();

		if(this.evtEnterVip){
			cc.vv.eventCustom.off("EnterVipRoom", this.evtEnterVip);
			this.evtEnterVip = null;
		}
		cc.systemEvent.off("EnterTable",this.enterVipRoom );
	}


	start() {

	}
	init(args) {
		cc.vv.MarqueeDataModel.close();
		this.from = args[0].lastScene || "";
		this.isOpenChongZhi = args[0].isOpenChongZhi || false;

		let node = cc.instantiate(this.hallUI);
		node.parent = this.UIRoot;
	}

	update(dt) {
		this.checkNewVersion(dt);
	}

	checkNewVersion(dt) {
	}

	hotUpError(args) {
		var errCode = args[0];
		console.log("____errCode = " + errCode + new Date());
		switch (errCode) {
			case cc.vv.hotUpdate.errorCode.NEED_UPDATE: //有热更版本
			case cc.vv.hotUpdate.errorCode.NEED_INSTALL: //需要重新下载安装
				//todo
				//	this.isVersionTip = true;
				console.log("_____have new version");
				cc.vv.GLUtils.showAlert1("有新版本需要更新！", function () {
					cc.vv.GLUtils.repetLogin(false);
				}.bind(this),
					null
				);
				break;
		}
	}

	openGame() {

	}
	/** 广播事件 create by tm */
	ServerNtc(_evt): void {
		if (!_evt) return;
		_evt = _evt[0];
		switch (_evt.cmd) {
			case `ATTChatMessageNtc`://收到服务器聊天消息通知
				this.ATTChatMessageNtc(_evt);
				break;
		}
	}
	/** 收到服务器聊天消息通知 */
	ATTChatMessageNtc(_evt): void {
		if (!_evt) return;
		if (_evt.rid != cc.vv.session.getRid()) {//只需要存其他人的
			//储存服务器聊天数据
			let _content = cc.vv.session.getChatContent(_evt.content);
			cc.vv.session.setChatData(_evt.chatid, _evt.type, {
				style: 1,
				type: _content.contentType,
				nick: _evt.rolename,
				content: _content.contentTxt,
				head: _evt.logo,
				rid: _evt.rid,
				itemY: 1,
                height: -1,
			});
			//储存menu
			if (_evt.type == 1 && !cc.vv.session.isPMenu(_evt.chatid, _evt.type)) {
				cc.vv.session.setPMenu({
					menuName: _evt.rolename,
					isChoose: false,
					isDelete: true,
					type: _evt.type,
					chatId: _evt.chatid
				});
			}
		}
	}
	test() {
	}

	enterVipRoom(){
		this.bg.spriteFrame = FPJDefine.isVipRoom() ? this.vipSpF : this.hallSpF;
	}
}
